#ifndef PLATNETUDP
#define PLATNETUDP
#include <winsock.h>
#include <vector>
#include <string>
#include <iostream>
#include "platinum.h"

namespace Platinum{
		namespace Net{
				
				/**
				* A packet is a struct containing only 2 std::string objects which represent the IP and data recieved in a UDP packet.
				*/
				struct Packet{
						std::string IP;  ///IP Address
						std::string Data; ///Data either recieved or sent depending on whether this packet is incoming or outgoing
				};
				
				/**
				*  MakeSocket creates a UDP socket and returns the file pointer to that socket, note: the socket file pointer is an INT
				*/
				SOCKET MakeSocket();				
				namespace UDP{
						
						/**
						*	The Listener Class is literally an ear to the ground class intended for listening for incoming data
						*	It is the Listen side of a client or server object.
						*/
						class Listener{
							private:		
								int iSock; /// Socket File Descriptor
								int iPort; /// Port
								struct sockaddr_in MyAddr;    /// My address information
								struct sockaddr_in TheirAddr; /// Connector address information
								int AddrLen; ///Length of Address
								int iNumBytes; ///Number of Bytes Recieved
								char sBuf[MAXBUF];  ///Buffer to hold things in.
								
							public:
								Listener(int port);								
								~Listener();
								
								/**
								*	Listen causes the Listener to block until data is recieved, 
								*	Listen returns a pointer to a Packet struct which has IP and Data members both are type string
								*	Ideally Listen should be called in a loop in a seperate thread, if you need to do anything else while waiting for Data
								*	Make sure to delete the packet returned when your are finished with it!
								*/
								Packet* Listen();						
						};
						
						/**
						*	The Sender Class is used for sending data out over UDP
						*	It is the send side of a persistant client object
						*/
						class Sender{
							
							private:
								int iSock;
								int iPort;
								struct sockaddr_in Dest;
								std::string IP;
								/**
								*	The SendAll function ensures all data gets sent.
								*/
								int SendAll(char *buf, int len);
								
							public:
								Sender(std::string ip,int port, int sock);
								~Sender();
								
								int Send(std::string Data);
						};
				}
		}
}
#endif